﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using emp.Utility;
using System.Collections;
using emp.Model.SysManage;
using System.Data;
using System.Data.SqlClient;
using emp.SqlServerDAL;

public partial class crm_salienceMember_SalienceMemberList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {   
        if (!IsPostBack)
        {
            inital();

        }
    }


    protected void gvquestlist_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {

        GridView theGrid = sender as GridView;
        int newPageIndex = 0;
        if (-2 == e.NewPageIndex)
        {
            TextBox txtNewPageIndex = null;
            GridViewRow pagerRow = theGrid.BottomPagerRow;
            if (null != pagerRow)
            {
                txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox;
            }
            if (null != txtNewPageIndex)
            {
                newPageIndex = int.Parse(txtNewPageIndex.Text) - 1;
            }
        }
        else
        {
            newPageIndex = e.NewPageIndex;
        }

        newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
        newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;
        theGrid.PageIndex = newPageIndex;
        inital();
    }

    void inital()
    {

        this.gvquestlist.DataSource = getDt();
        this.gvquestlist.DataBind();
        if (getDt().Rows.Count == 0)
        {
            LBjl.Visible = true;
        }
        else
        {
            LBjl.Visible = false;
        }
    
    }



    //protected void PageChanged(object sender, GridViewPageEventArgs e)
    //{

    //    gview(e.NewPageIndex);

    //}

    //private void gview(int page)
    //{


    //    campaignList.PageIndex = PageUtil.getGviewNewPage(campaignList, page);
    //    this.pageNum.Value = campaignList.PageIndex.ToString();

    //    IList clist = (IList)Session["JY_UPLOAD_DETAIL_02"];

    //    this.campaignList.DataSource = clist;
    //    this.campaignList.DataBind();

    //    PageUtil.setPageCount(campaignList, clist);

    //}
   
    protected void recBtn_Click(object sender, EventArgs e)
    {
        Response.Redirect("UpMember.aspx", true);
    }


    private DataTable getDt() 
    {
        DataTable dt = null;
        string sql = "SELECT TCI_ID      ,TCI_NAME      ,TCI_GANDER      ,TCI_TELEPHONE      ,TCI_CAR_MODEL      ,TCI_PLAN_TIME      ,TCI_BUDGET_PUR      ,TCI_IS_CONTACT      ,TCI_IS_TEST      ,TCI_PROVINCE      ,TCI_CITY      ,TCI_DEALER_INTENTION      ,TCI_BRAND_OWNED      ,TCI_MODEL_OWNED      ,TCI_NOTES      ,TCI_TCB_ID  FROM TASTE_CAR_INFORMATION  WHERE 1=1";

        if (BEGN.Text != null && BEGN.Text != "")
        {
            sql += " and  [TCI_DATE]>='" + BEGN.Text + " 00:00:00'";
        }
        if (END.Text != null && END.Text != "")
        {
            sql += " and  [TCI_DATE]<='" + END.Text + " 23:59:59'";
        }

        

        if (TCI_NAME.Text != null && TCI_NAME.Text != "")
        {
            sql += " and  [TCI_NAME]='" + TCI_NAME.Text + "'";
        }
        if (TCI_TELEPHONE.Text != null && TCI_TELEPHONE.Text != "")
        {
            sql += " and  [TCI_TELEPHONE]='" + TCI_TELEPHONE.Text + "'";
        }
        sql += "   order by TCI_ID desc";

        dt = getTableInfo(sql);
        return dt;
    }


    protected void selectBtn_Click(object sender, EventArgs e)
    {

        inital();
        
    }


    private DataTable getTableInfo(string sql)
    {
        DataSet data = new DataSet();
        using (SqlDataAdapter sda = new SqlDataAdapter())
        {
            try
            {
                sda.SelectCommand = new SqlCommand();
                sda.SelectCommand.CommandText = sql;
                sda.SelectCommand.Connection = new SqlConnection(SQLHelper.CONN_STRING_NON_DTC);
                sda.Fill(data);
            }
            catch { }
        }
        return data.Tables[0];
    }
}
